import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (location) {
return originalPush.call(this, location).catch(err => err)
}

export const routes = [
  {
    path: '/',
    redirect: '/login'
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('../views/Login/index.vue')
  },
  {
    path: '/404',
    name: '404',
    component: () => import('../views/Error/404.vue')
  },
  {
    path: '/index',
    name: 'Index',
    component: ()=> import('../views/Index.vue'),
    meta: {
      requireAuth: true
    },
    children:[
      {
        path:'/home',
        name: 'Home',
        component: () => import('../views/Home/index.vue')
      },
      {
        path:'/tongzhi',
        name: 'TongZhi',
        component: () => import('../views/Notice')
      },
      {
        path:'/experts-pingfen',
        name: 'PingFen',
        component: () => import('../views/experts/PingFen')
      },
      {
        path:'/experts-biaoji',
        name: 'ExpertsBiaoji',
        component: () => import('../views/experts/BiaoJi')
      },
      {
        path:'/experts-xiangmu',
        name: 'XiangMu',
        component: () => import('../views/experts/XiangMu')
      },
      {
        path:'/experts-xiangmulist',
        name: 'XiangMuList',
        component: () => import('../views/experts/XiangMu/list.vue')
      },
      {
        path:'/xiangmu-details',
        name: 'XiangMuDetails',
        component: () => import('../views/experts/XiangMu/details.vue')
      },
      {
        path:'/experts-list',
        name: 'ExpertsShenBaoList',
        component: () => import('../views/experts/ShenBao/list.vue')
      },
      {
        path:'/experts-shenbao',
        name: 'ExpertsShenBao',
        component: () => import('../views/experts/ShenBao')
      },
      {
        path:'/shenbao-details',
        name: 'ShenBaoDetails',
        component: () => import('../views/experts/ShenBao/details.vue')
      },
      // 项目申报
      {
        path:'/shenbao-home',
        name: 'ShenBaoHome',
        component: () => import('../views/Home/shenbao.vue')
      },
      {
        path:'/declare-biaoji',
        name: 'DeclareBiaoji',
        component: () => import('../views/declare/BiaoJi')
      },
      {
        path:'/declare-list',
        name: 'DeclareList',
        component: () => import('../views/declare/ShenBao/list.vue')
      },
      {
        path:'/declare-shenbao',
        name: 'DeclareShenBao',
        component: () => import('../views/declare/ShenBao/index.vue')
      },
      {
        path:'/declare-xiangmu',
        name: 'DeclareXiangmu',
        component: () => import('../views/declare/XiangMu/index.vue')
      },
      {
        path:'/dshenbao-details',
        name: 'DShenBaoDetails',
        component: () => import('../views/declare/ShenBao/details.vue')
      },
      {
        path:'/shenbaozhongxin',
        name: 'ShenBaoZhongXin',
        component: () => import('../views/declare/ShenBaoZhongXin/index.vue')
      },
      {
        path:'/shenbaozhongxin-modify',
        name: 'ShenBaoZhongXinModify',
        component: () => import('../views/declare/ShenBaoZhongXin/modify.vue')
      },
      // 学校管理员
      {
        path: '/school-home',
        name: 'SchoolHome',
        component: () => import('../views/Home/school.vue')
      },
      {
        path:'/school-biaoji',
        name: 'Biaoji',
        component: () => import('../views/school/BiaoJi')
      },
      {
        path:'/school-list',
        name: 'ShenBaoList',
        component: () => import('../views/school/ShenBao/list.vue')
      },
      {
        path:'/school-shenbao',
        name: 'ShenBao',
        component: () => import('../views/school/ShenBao/index.vue')
      },
      {
        path:'/school-xiangmu',
        name: 'ShenBaoXiangmu',
        component: () => import('../views/school/XiangMu/index.vue')
      },
      {
        path:'/school-details',
        name: 'SchoolDetails',
        component: () => import('../views/school/ShenBao/details.vue')
      },
      {
        path: '/user-management',
        name: 'UserManagement',
        component: () => import('../views/school/UserManagement')
      },
      {
        path: '/create-user',
        name: 'CreateUser',
        component: () => import('../views/school/UserManagement/create.vue')
      },
      // 修改申报用户信息
      {
        path: '/modify-user',
        name: 'ModifyUser',
        component: () => import('../views/school/UserManagement/modify.vue')
      },
      {
        path: '/info-maintenance',
        name: 'InfoMaintenance',
        component: () => import('../views/school/InfoMaintenance')
      },
      // 修改个人信息
      {
        path:'/modify',
        name: 'Modify',
        component: () => import('../views/Modify')
      },
      // 修改密码
      {
        path: '/modify-pass',
        name: 'ModifyPass',
        component: () => import('../views/ModifyPass')
      },
      {
        path:'/register',
        name: 'Register',
        component: () => import('../views/Register')
      },
      {
        path:'/list',
        name: 'List',
        component: () => import('../views/list.vue'),
        redirect: '/list-zhengce',
        children:[
          {
            path:'/list-zhengce',
            name: 'ZhengCe',
            component: () => import('../views/ZhengCe'),
          },
          {
            path: '/list-gonggao',
            name: 'GongGao',
            component: () => import('../views/GongGao')
          },
          {
            path: '/policylist',
            name: 'policyList',
            component: () => import('../views/policyList')
          }
        ]
      },
      {
        path: '/list-details',
        name: 'ListDetails',
        component: () => import('../views/ListDetails')
      },
      {
        path: '/details',
        name: 'Details',
        component: () => import('../views/Details/index.vue')
      },
      // 报错
      {
        path: '/dataError',
        name: 'DataError',
        component: ()=> import('../views/Error/data404.vue')
      },
      {
        path: '/overdueError',
        name: 'OverdueError',
        component: ()=> import('../views/Error/overdue404.vue')
      },
      {
        path: '/rootError',
        name: 'RootError',
        component: ()=> import('../views/Error/root404.vue')
      }
    ]
  },
  {
    path: '/noDetails',
    component: ()=> import('../views/noLogin/details.vue'),
  },
  {
    path: '/noZhengce',
    component: ()=> import('../views/noLogin/zhengce.vue'),
  },
  {
    path: '/noGonggao',
    component: ()=> import('../views/noLogin/gonggao.vue'),
  },
  {
    path: '/about',
    name: 'About',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  }
]

const createRouter = () => new VueRouter({
  // mode: 'history', // require service support
  // mode: 'hash',
  routes: routes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
